﻿using PC.AzureMultiApp.Core.Applications;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using PC.AzureMultiApp.Core.Models;
using System.Collections.Generic;
using PC.AzureMultiApp.Storage.Moles;
using PC.AzureMultiApp.Storage;

namespace Core.Test
{
    
    
    /// <summary>
    ///This is a test class for ApplicationsTest and is intended
    ///to contain all ApplicationsTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ApplicationsTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        [TestMethod()]
        [HostType("Moles")]
        public void DeleteTest()
        {
            MApplicationDataSource.Constructor = (a) => { };

            MApplicationDataSource.AllInstances.GetAll = (datasource)
             =>
            {
                return new List<AzureApplicationEntity>() { new AzureApplicationEntity() { UniqueId = "uniqueId" } };
            };

            bool called = false;
            MApplicationDataSource.AllInstances.DeleteAzureApplicationEntity = (a, app)
                =>
            {
                Assert.IsNotNull(app);
                Assert.IsFalse(app.IsWebDeploy);
                called = true;
            };

            string id = "uniqueId";
            Applications.Delete(id);

            Assert.IsTrue(called);
            
        }

        [TestMethod()]
        [HostType("Moles")]
        public void Delete_NoExists_Test()
        {
            MApplicationDataSource.Constructor = (a) => { };

            MApplicationDataSource.AllInstances.GetAll = (datasource)
             =>
            {
                return new List<AzureApplicationEntity>() { new AzureApplicationEntity() { UniqueId = "uniqueId" } };
            };

            bool called = false;
            MApplicationDataSource.AllInstances.DeleteAzureApplicationEntity = (a, app)
                =>
            {
                Assert.IsNotNull(app);
                Assert.IsFalse(app.IsWebDeploy);
                called = true;
            };

            string id = "no_exists";
            Applications.Delete(id);

            Assert.IsFalse(called);

        }

        [TestMethod()]
        [HostType("Moles")]
        public void Delete_NoResults_Test()
        {
            MApplicationDataSource.Constructor = (a) => { };

            MApplicationDataSource.AllInstances.GetAll = (datasource)
             =>
            {
                return new List<AzureApplicationEntity>() {  };
            };

            bool called = false;
            MApplicationDataSource.AllInstances.DeleteAzureApplicationEntity = (a, app)
                =>
            {
                Assert.IsNotNull(app);
                Assert.IsFalse(app.IsWebDeploy);
                called = true;
            };

            string id = "no_exists";
            Applications.Delete(id);

            Assert.IsFalse(called);

        }


        [TestMethod()]
        [HostType("Moles")]
        public void GetAllTest()
        {
            MApplicationDataSource.Constructor = (a) => { };

            bool called = false;
            MApplicationDataSource.AllInstances.GetAll = (datasource)
             =>
            {
                called = true;
                return new List<AzureApplicationEntity>() { };
            };

            Applications.GetAll();
            Assert.IsTrue(called);
        }

        [TestMethod()]
        [HostType("Moles")]
        public void InsertTest()
        {
            ApplicationModel app = new ApplicationModel();

            MApplicationDataSource.Constructor = (a) => { };

            bool called = false;
            MApplicationDataSource.AllInstances.InsertAzureApplicationEntity = (dataosurce, application)
             =>
            {
                called = true;
            };

            Applications.Insert(app);
            Assert.IsTrue(called);
        }

        [TestMethod()]
        [HostType("Moles")]
        public void EditTest()
        {
            MApplicationDataSource.Constructor = (a) => { };

            bool called = false;
            MApplicationDataSource.AllInstances.UpdateStringAzureApplicationEntity = (dataosurce, updateId, application)
             =>
            {
                called = true;
            };

            string id = "uniqueId";
            ApplicationModel app = new ApplicationModel();
            Applications.Edit(id, app);
            Assert.IsTrue(called);
        }



    }
}
